<?php
/**
 * Var dump that shows paths for arrays
 * @param $data	object to dump
 * @param $methods show methods from objects
 * @param $level	maximum nesting level (to prevent infinite loops)
 */
function var_dump_path($data, $methods = false, $maxdepth = 20, $path = '', $level = 0, $aRecursives = array())
{
	echo '<span style="10px; font-family: Verdana; font-size: 10px; color: black">';
	
	if(is_array($data) || is_object($data))
	{
			if($level < $maxdepth)
			{
				if(is_object($data))
				{
					echo '<span style=""><b>'.$path.'</b>: <i>'.get_class($data).' object</i></span><br />';										
					$aRecursives[] = $data;
					if($methods)
					{
						$methods = get_class_methods($data);
						$data = get_object_vars($data);
						foreach($methods as $method)
						{
							$data[$method.'()'] = 'method';
						}
					}
					else
					{
						$data = get_object_vars($data);						
					}
					
					$bObject = true;
				}
				else
				{
					$aRecursives[] = print_r($data, true);
					echo '<b>'.$path.'</b>: <i>Array</i><br />';	
				}
				
				foreach($data as $key => $value)
				{
					$sArray = '[<span style="color:green;">'."'".$key."'</span>]";					
					$sObj = '-><span style="color:blue;">'.$key.'</span>';					
					
					if(($bObject && in_array($value, $aRecursives, true)) || (!$bObject && in_array(print_r($value, true), $aRecursives)))
					{
						if($bObject)
						{
							echo '<span style="background-color: #FFEEEE"><b>'.$path.$sObj .'</b>: <i>Recursive</i></span><br />';
						}
						else
						{
							echo '<span style="background-color: #FFEEEE"><b>'.$path.$sArray .'</b>: <i>Recursive</i></span><br />';
						}						
					}
					else
					{
						if(is_int($key))
						{
							var_dump_path($value, $methods, $maxdepth, $path . '[<span style="color:red; font-size:9px;">'.$key.'</span>]', $level + 1, $aRecursives);						
						}
						else
						{
							if($bObject)
							{
								var_dump_path($value, $methods, $maxdepth, $path . $sObj, $level + 1, $aRecursives);								
							}
							else
							{
								var_dump_path($value, $methods, $maxdepth, $path . $sArray, $level + 1, $aRecursives);
							}						
						}
					}
				}
			}
			else
			{
				if(is_object($data))
				{
					echo '<span style="background-color: #FFEEEE"><b>'.$path.'</b>: <i>'.get_class($data).' object (too deep)</i></span><br />';										
				}
				else
				{
					echo '<span style="background-color: #FFEEEE"><b>'.$path.'</b>: <i>Array (too deep)</i><br />';	
				}
				echo '<div style="width: 100%; height: 10px; background-color: #FFEEEE; margin-top: -10px">&nbsp;</div>';
			}		
	}
	else if(!$data)
	{
		echo '<b>'.$path .'</b>: <i>null</i><br />';
	}
	else
	{
		echo '<b>'.$path .'</b>: '. htmlspecialchars((string)$data) .'<br />';
	}
	echo '</span>';
}